<?php
$title='留言列表';
include 'header.php';
if (isset($_GET["deldata"])){
    $id=daddslashes($_GET["deldata"]);
try {
    $del=$pdo->exec("DELETE FROM 9g_prize WHERE id = {$id}");
    if ($del){
        exit("<script>alert('删除成功');location.href='./prizelist.php?page=1';</script>");
    }
}catch (Exception $e){

}
}
?>
<!--页面主要内容-->

<main class="mn-inner">
                <div class="row">
                    <div class="col s12">
                        <div class="page-title">留言列表</div>
                    </div>
                    <div class="col s12 m12 l12">
                        <div class="card">
                            <div class="card-content">
                                <span class="card-title">基本操作</span>
                                <button onclick="return deletess();" class="waves-effect waves-light btn red m-b-xs">清空</button>
                                <br>
                                <table id="example" class="display responsive-table datatable-example">
                                    <thead>
                                        <tr>
                                            <th>留言对象</th>
                                            <th>抽中奖品</th>
                                            <th>留言内容</th>
                                            <th>留言IP</th>
                                            <th>留言时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tfoot>
                                    <tr>
                                            <th>留言对象</th>
                                            <th>抽中奖品</th>
                                            <th>留言内容</th>
                                            <th>留言IP</th>
                                            <th>留言时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </tfoot>
                                    <tbody>
                                        <?php
                                        try {
                                            $query=$pdo->query("SELECT * FROM 9g_msg");
                                            while($row=$query->fetch(PDO::FETCH_ASSOC)){
                                                echo ' <tr>
                                                <td>'.$row["qq"].'</td>
                                                <td>'.$row["name"].'</td>
                                                <td>'.$row["msg"].'</td>
                                                <td>'.$row["ip"].'</td>
                                                <td>'.$row["date"].'</td>
                                                <td>
                                                <button onclick="return deletes('.$row["id"].');" class="btn-floating btn-xs   red"><i class="material-icons">delete</i></button>
                                                </td>
                                            </tr>';
                                            }
                                        } catch (\Throwable $th) {
                                            //throw $th;
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
            <script src="assets/plugins/jquery/jquery-2.2.0.min.js"></script>
        <script src="assets/plugins/materialize/js/materialize.min.js"></script>
        <script src="assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
        <script src="assets/plugins/jquery-blockui/jquery.blockui.js"></script>
        <script src="assets/plugins/datatables/js/jquery.dataTables.min.js"></script>
        <script src="assets/js/alpha.min.js"></script>
        <script src="assets/js/pages/table-data.js"></script>
        <script src="assets/plugins/sweetalert/sweetalert.min.js"></script>
<script language="JavaScript">
        function deletes(del) {
        var id = del;
        swal({   
    title: "你确定要删除此条数据吗?",
    text: "删除后将不可恢复",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "确定",
    closeOnConfirm: false,
}, function(){
        $.ajax({
            type: "POST",
            url: "set.php?act=delmsg",
            data: {
                id: id
            },
            dataType: "json",
            success: function(data) {
                if (data.state == 1) {
                    swal("删除成功!", "恭喜你，删除成功!", "success");
                    setTimeout(function() {
                        window.location = './msglist.php';
                    }, 1000);
                }else{
                    swal("删除失败!", "删除失败!", "error");
                }

            },
            error: function(data) {

            }
        });
});
}

    function deletess(){
        swal({   
    title: "敏感操作",
    text: "你确定删除所有数据吗？",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "确定",
    cancelButtonText: "点错了",
    closeOnConfirm: false,
}, function(isConfirm){
    if (isConfirm) {
        $.ajax({
            type: "POST",
            url: "set.php?act=delsmsg",
            data: {
               act:'act'
            },
            dataType: "json",
            success: function(data) {
                if (data.state == 1) {
                    swal("清空成功!", "恭喜你，清空成功了!", "success");
                    setTimeout(function() {
                        window.location = './msglist.php';
                    }, 1000);
                }else{
                    swal("清空失败!", "清空失败，可能无信息!", "error");
                }

            },
            error: function(data) {

            }
        });
    }
}); 
}
</script>
</body>
</html>